{% macro render_form(form, action) %}
    <form class="form-horizontal" method="post" action="{{ action }}" enctype="multipart/form-data">
        {{ form.csrf_token }}
        {% for field in form %}
            {% if field.type == "CSRFTokenField" or field.type == "HiddenField" %}
                {{ field }}
            {% else %}
                <div class="control-group {% if field.errors %}error{% endif %}">
                    {% if field.flags.required %}
                        {{ field.label(class="control-label required") }}
                    {% else %}
                        {{ field.label(class="control-label") }}
                    {% endif %}
                    <div class="controls">
                        {{ field }}
                        {% if field.errors %}
                            <span class="help-inline">{{ field.errors|join(', ') }}</span>
                        {% elif field.description %}
                            <span class="help-inline">{{ field.description }}</span>
                        {% endif %}
                    </div>
                </div>
            {% endif %}
        {% endfor %}
        <div class="form-actions">
            {{ caller() }}
        </div>
    </form>
{% endmacro %}

{% macro render_stars(number, max) %}
        {% if number < 0 %}
        <span title="(no ratings)" class="ratings">
            {% for i in range(max) %}
                <i class="icon-star-empty off"></i>
            {% endfor %}
        {% else %}
        <span title="(rating {{ number }} out of {{ max }})" class="ratings">
            {% for i in range(number) %}
                <i class="icon-star on"></i>
            {% endfor %}
            {% for i in range(max-number) %}
                <i class="icon-star off"></i>
            {% endfor %}
        {% endif %}
    </span>
{% endmacro %}

{% macro render_avatar(user_profile, size=32, class='img-polaroid') %}
    <img class="{{ class }}" src="{{ user_profile.email|gravatar_url(size) }}"
         alt="{{ _('Avatar of') }}{{ user_profile.display_name }}">
{% endmacro %}
